{extend name="Base" /}
{block name="title"}{$title}{/block}
{block name="body"}
<fieldset class="layui-elem-field layui-field-title">
	<legend>{$name}</legend>
</fieldset>

<table id="msg" lay-filter="msg" class="layui-hide"></table>
<script type="text/html" id="msg_bar">
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="re">查看</a>
</script>

<script>
	layui.use(['table', 'element', 'layer', 'form'], function () {
		var table = layui.table;
		var layer = layui.layer;

		table.render({
			id: "msg",
			elem: '#msg',
			page: true,
			height: "full-200",
			even: true,
			method: 'post',
			limit: 30,
			where: {},
			url: "/backend/index/getRes",
			cols: [[
				{field: 'file', title: '源码文件', width: 600},
				{field: 'revision', title: '提交版本', width: 150},
				{field: 'author', title: '提交作者', width: 300},

				{title: '查看差异', width: 100, align: 'center', toolbar: '#msg_bar', fixed: 'right'}
			]]
		});

		table.on('tool(msg)', function (obj) {
			var data = obj.data;
			var d = {
				url: data.url,
				file: data.file,
				revision: data.revision
			};

			$.ajax({
				type: "POST",
				url: "/backend/index/getDiff",
				cache: false,
				data: d,
				dataType: "json",
				success: function (e) {
					var mode;
					if (e.error_code === 0) {
						mode = "查看 " + e.preRev + "版本 与 " + e.curRev + "版本 的差异"
					} else {
						mode = "查看 " + e.curRev + "版本 和上一版本的差异"
					}
					var needEncode = HTMLEncode(e.data);
					layer.open({
						type: 0,
						title: mode,
						closeBtn: 1,
						btn: ['关闭'],
						area: ['auto', '600px'],
						shade: 0.8,
						id: 'see',
						btnAlign: 'c',
						content: "<pre>" + needEncode + "</pre>"
					});
				}
			});
		});
	});

	function HTMLEncode(str) {
		//禁止HTML解析
		str = str.replace(/&/g, '&amp;');
		str = str.replace(/</g, '&lt;');
		str = str.replace(/>/g, '&gt;');
		str = str.replace(/"/g, '&quot;');
		str = str.replace(/'/g, '&#039;');
		return str;
	}
</script>
{/block}